<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.search" placeholder="关键词" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('sys:user:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <!-- <el-button v-if="isAuth('sys:user:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
          prop="id"
          header-align="center"
          align="center"
          width="120"
          label="节点ID">
      </el-table-column>
      <el-table-column
        v-if="isAuth('bzz:bzzNode:ip')"
        prop="ip"
        header-align="center"
        align="center"
        width="120"
        label="IP">
      </el-table-column>
      <el-table-column
        prop="no"
        width="100"
        header-align="center"
        align="center"
        label="no">
      </el-table-column>
      <el-table-column
        prop="ethEreum"
        header-align="center"
        align="center"
        label="eth地址">
      </el-table-column>
      <el-table-column
        prop="chequebookAddress"
        header-align="center"
        align="center"
        label="合约地址">
      </el-table-column>
      <el-table-column
        prop="count"
        header-align="center"
        align="center"
        width="100"
        label="出票数">
      </el-table-column>
      <el-table-column
        prop="balance"
        header-align="center"
        align="center"
        width="120"
        label="xBzz余额">
      </el-table-column>
      <el-table-column 
        header-align="center"
        align="center"
         width="120"
        label="出票详情">
          <template slot-scope="scope">
         <el-button
          plain
          size="mini"
          type="primary"
          @click="handleDelete(scope.row)">查看</el-button>
          </template>
    </el-table-column>
      <!-- <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.userId)">修改</el-button>
          <el-button v-if="isAuth('sys:user:delete')" type="text" size="small" @click="deleteHandle(scope.row.userId)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

      <el-dialog title="出票详情" :visible.sync="dialogTableVisible">
      <el-table :data="gridData" style="width: 100%">
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        width="120"
        label="id">
      </el-table-column>
      <el-table-column
        prop="nodeId"
        header-align="center"
        align="center"
        width="100"
        label="节点id">
      </el-table-column>
      <el-table-column
        prop="count"
        header-align="center"
        align="center"
        width="100"
        label="出票数">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        width="180"
        label="汇报时间">
      </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandleA"
        @current-change="currentChangeHandleA"
        :current-page="pageIndexA"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSizeA"
        :total="totalPageA"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-dialog>
  </div>
</template>

<script>
/* eslint-disable */ 
  import AddOrUpdate from '../sys/user-add-or-update'
  export default {
    data () {
      return {
        gridData: [],
        dataForm: {
          search: ''
        },
        dialogTableVisible: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],

        pageIndexA: 1,
        pageSizeA: 10,
        totalPageA: 0,
        id:null
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 出票详情
      handleDelete(row){
        if(row){
          this.id = row.id
        }
        this.dialogTableVisible = true
        // console.log(row)
        this.$http({
          url: this.$http.adornUrl('/bzz/nodeCheckList'),
          method: 'post',
          data: this.$http.adornData({
              'nodeId':this.id,
              'page':this.pageIndexA,
              'limit':this.pageSizeA,
            })
        }).then(({data}) => {
          if (data && data.code === 0) {
            console.log(data);
            this.gridData = data.page.list
             this.totalPageA = data.page.totalCount
          } else {
            this.gridData = []
          }
        })
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/bzz/nodeList'),
          method: 'post',
          data: this.$http.adornData({
              'searchWord':this.dataForm.search,
              'page':this.pageIndex,
              'limit':this.pageSize,
            })
        }).then(({data}) => {
          if (data && data.code === 0) {
            // eslint-disable-next-line
            console.log(data);
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },

      // 子每页数
      sizeChangeHandleA (val) {
        this.pageSizeA = val
        this.pageIndexA = 1
        this.handleDelete()
      },
      // 子当前页
      currentChangeHandleA (val) {
        this.pageIndexA = val
        this.handleDelete()
      },

      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
    }
  }
</script>

<style lang="">
    .el-dialog{min-width: 560px;}
</style>
